#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define pb push_back
using namespace std;

const string etable[101] =
{"","H","He",
"Li","Be","B","C","N","O","F","Ne",
"Na","Mg","Al","Si","P","S","Cl","Ar",
"K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr",
"Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn","Sb","Te","I","Xe",
"Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl","Pb","Bi","Po","At","Rn",
"Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm"};

int n,k;
int an[20],ak[20],ans[20],cnt=0;
bool done[1<<20];
vector<int> syn[20];

int getNum(string &s)
{
        for(int i=1;i<101;i++) if(etable[i]==s)
                return i;
}
int getSum(int binum)
{
        int sum=0;
        for(int i=0;i<n;i++) if(1<<i&binum)
        {
                sum+=an[i];
        }
        return sum;
}
void getSyn(int ki)
{
        int maxn=1<<n;
        for(int i=0;i<maxn;i++) if(getSum(i)==ak[ki])
        {
                syn[ki].pb(i);
        }
}
bool getAns(int ki,int binum)
{
        if(done[binum]) return false;
		if(ki==k) return true;
		done[binum] = true;
        for(int i=0;i<syn[ki].size();i++)
        {
			cnt++;
                if((binum&syn[ki][i])==0)
                {
                        if(getAns(ki+1,binum|syn[ki][i]))
                        {
                                ans[ki]=syn[ki][i];
                                return true;
						}
                }
        }
        return false;
}
void printAns(int ki)
{
        bool plusf=false;
        //printf("ans[%d]=%d\n",ki,ans[ki]);
        for(int i=0;i<n;i++) if(1<<i&ans[ki])
        {
                if(plusf) putchar('+');
                cout<<etable[an[i]];
                plusf=true;
        }
        cout<<"->"<<etable[ak[ki]]<<endl;
}
int main()
{
        string ss;
        cin>>n>>k;
        for(int i=0;i<n;i++)
        {
                cin>>ss;
                an[i]=getNum(ss);
        }
        for(int i=0;i<k;i++)
        {
                cin>>ss;
                ak[i]=getNum(ss);
                getSyn(i);
        }
        if(getAns(0,0))
        {
                puts("YES");
                for(int i=0;i<k;i++) printAns(i);
        }
        else puts("NO");
        //cout<<cnt<<endl;
        return 0;
}
/*
17 4
He He He He He He He He He He He He He He He He He
Si Ar H H
*/
